//
// Created by dyc on 25-1-4.
//

#include "camera.h"

namespace hitcrt {
    /**
     *
     * @param id 摄像头索引
     * @param width 图像分辨率宽
     * @param height 图像分辨率高
     * @param FPS 帧率
     * @param Brightness 亮度
     * @param Contrast 对比度
     * @param Saturation 饱和度
     * @param Auto_Exposure 曝光模式
     * @param Exposure 曝光时间
     *
     */
    void Camera::set(const int id, const int width, const int height, const double FPS, const double Brightness,
                     const double Contrast, const double Saturation, const double Auto_Exposure, const double Exposure) {
        this->ID = id;
        this->Width = width;
        this->Height = height;
        this->FPS = FPS;
        this->Brightness = Brightness;
        this->Contrast = Contrast;
        this->Saturation = Saturation;
        this->Auto_Exposure = Auto_Exposure;
        this->Exposure = Exposure;
    }

    int Camera::open() {
        cap.open(ID,cv::CAP_V4L2);
        cap.set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('M', 'J', 'P', 'G'));
        if (!cap.isOpened()) {
            std::cerr << "无法打开摄像头" << std::endl;
            return -1;
        }
        cap.set(cv::CAP_PROP_FPS, FPS);//帧率
        cap.set(cv::CAP_PROP_BRIGHTNESS, Brightness); // 亮度，范围通常为0到1
        cap.set(cv::CAP_PROP_CONTRAST, Contrast); // 对比度，范围通常为0到1
        cap.set(cv::CAP_PROP_SATURATION, Saturation); // 饱和度，范围通常为0到1
        cap.set(cv::CAP_PROP_AUTO_EXPOSURE, Auto_Exposure); // 曝光模式
        cap.set(cv::CAP_PROP_EXPOSURE, Exposure); // 曝光度，负值表示自动曝光，正值表示手动曝光

        // 获取实际的帧率
        actual_FPS = cap.get(cv::CAP_PROP_FPS);

        return 1;
    }


}
